#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging


class Logger:
    logger = None

    def __init__(self):
        if not Logger.logger:
            Logger.logger = logging.getLogger("root")
            Logger.logger.setLevel(logging.DEBUG)
            # 建立一个streamhandler来把日志打在CMD窗口上，级别为error以上
            ch = logging.StreamHandler()
            ch.setLevel(logging.DEBUG)
            # 设置日志格式
            formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
            ch.setFormatter(formatter)
            # 将相应的handler添加在logger对象中
            Logger.logger.addHandler(ch)

    def getLogger(self):
        return Logger.logger
